package progress.exa36;

public class HashCodeStudy {

    int i;

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        try {
            if(this.i== obj.getClass().getField("i").getInt(obj)){
                return true;
            }
        } catch (IllegalAccessException | NoSuchFieldException e) {
            e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {
        HashCodeStudy obj1 = new HashCodeStudy();
        obj1.i = 1;
        HashCodeStudy obj2 = new HashCodeStudy();
        obj2.i = 1;
        System.out.println("obj1和obj2的内容是否相等？");
        System.out.println(obj1.equals(obj1));
        System.out.println("obj1和obj2的hashCode是否相等？");
        System.out.println(obj1.hashCode()==obj2.hashCode());
    }
}
